package com.itzjc.config;

import com.itzjc.interceptor.CorsInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截配置类
 *

 *  2021-06-04 16:45
 **/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public CorsInterceptor corsInterceptor() {
        return new CorsInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
         //拦截全部路径，需要放到最上面
        registry.addInterceptor(corsInterceptor()).addPathPatterns("/**");


        WebMvcConfigurer.super.addInterceptors(registry);
    }

}
